// cpp
#include <stdio.h>
#include <iostream> 
#include <ctime> 
#include <cstdio>
#include <cstdlib>
#include <vector>

// allegro
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro5.h>
#include <allegro5\allegro_ttf.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_primitives.h>

// mine
#include "LevelGenerator.h"
#include "Player.h"
#include "Block.h"
#include "Vector2.h"

#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 480

void LoadAndTestLevel()
{
	ALLEGRO_BITMAP* background = al_load_bitmap("amazon.png");

	Scene* scene = LevelGenerator::GetInstance()->CreateScene(2,background);
	std::map<Player, std::vector<Block>>::const_iterator iter; // always use const iterator

	int i  = 1;
	for (auto iter = scene->blocks.begin(); iter != scene->blocks.end(); iter++)
	{
		// Test for player
		Player p = iter->first;
		printf("Index player: %d\n", p.GetPlayerIndex());
		if (p.GetPlayerIndex() == i)
		{
			printf("Correto para player: %d\n", i);
		}
		i++;

		std::vector<Block> blocks = iter->second;

		//Test for blocks
		for (int k = blocks.size() - 1; k >= 0; k--)
		{
			Block b = blocks.at(k);
		//	printf("Block index: %d -- Iterator: %d\n", b.myIndex, k);
		/*	if (b.myIndex == k)
			{
				printf("Correto para o bloco: %d\n", k);
			}*/

			if (b.GetPosition().X == 300)
			{
				printf("Correto para o bloco: %d\n", k);
			}
			if (b.GetPosition().Y == 30)
			{
				printf("Correto para o bloco: %d\n", k);
			}
		}
	}
}

void LoadContent()
{
	// LoadAndTestLevel(); not ready yet so don't call it!!!!
}

int main(int argc, char **argv)
{
	
	ALLEGRO_DISPLAY *display = NULL;
 
  if(!al_init()) 
  {
    al_show_native_message_box(NULL, NULL, NULL, 
                 "failed to initialize allegro!", NULL, NULL);                   
    return -1;
  }
 
  display = al_create_display(640, 480);

  
  if(!display) 
  {
    al_show_native_message_box(NULL, NULL, NULL, 
                "failed to initialize display!", NULL, NULL);
    return -1;
  }

  al_init_image_addon();
 
  LoadContent();

  al_clear_to_color(al_map_rgb(0,0,0));
  al_flip_display();
  al_rest(20.0);
  al_destroy_display(display);

  return 0;
}